import { createRouter, createWebHashHistory } from "vue-router";

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    { path: '/', redirect: '/home' },
    { path: '/login', component: () => import('./components/Login.vue') },
    {
      path: '/home',
      component: () => import('./components/Home.vue'),
      redirect: '/home/shouye',
      children: [
        { path: 'shouye', component: () => import('./components/subcomponents/ShouYe.vue') },
        { path: 'zhongxin', component: () => import('./components/subcomponents/ZhongXin.vue') },
        { path: 'shouye/orders/AA', component: () => import('./components/subcomponents/GeReng/move/AA.vue'), props: true },
        { path: 'shouye/orders/AB', component: () => import('./components/subcomponents/GeReng/move/AB.vue'), props: true },
        { path: 'shouye/orders/AC', component: () => import('./components/subcomponents/GeReng/move/AC.vue'), props: true },
        { path: 'shouye/orders/AD', component: () => import('./components/subcomponents/GeReng/move/AD.vue'), props: true },
        { path: 'shouye/orders/AE', component: () => import('./components/subcomponents/GeReng/move/AE.vue'), props: true },
        { path: 'shouye/orders/AF', component: () => import('./components/subcomponents/GeReng/move/AF.vue'), props: true },
        { path: 'shouye/menu', component: () => import('./components/subcomponents/GeReng/sub/MyMenu.vue') },
        { path: 'jieshao', component: () => import('./components/subcomponents/JieShao.vue') },
        { path: 'sheng', component: () => import('./components/win/Sheng.vue') },
        { path: 'dan', component: () => import('./components/win/Dan.vue') },
        { path: 'jing', component: () => import('./components/win/Jing.vue') },
        { path: 'mo', component: () => import('./components/win/Mo.vue') },
        { path: 'zhongxin', component: () => import('./components/subcomponents/ZhongXin.vue'),
          redirect: '/home/zhongxin/wenchuang',
          children: [
            { path: 'wenchuang', component: () => import('./components/win/WenChuang.vue') },
            { path: 'yanchu', component: () => import('./components/win/YanChu.vue') },
          ]
        },
        { path: '/home/zhongxin/yanchu/chanpin', component: () => import('./components/win/ChanPin.vue') },
        { path: '/home/zhongxin/yanchu/bian', component: () => import('./components/win/Bian.vue') },
        { path: '/home/zhongxin/yanchu/feng', component: () => import('./components/win/Feng.vue') },
        { path: '/home/zhongxin/yanchu/xiong', component: () => import('./components/win/Xiong.vue') },
        { path: 'guanyu', component: () => import('./components/subcomponents/GuanYu.vue'),
          children: [
            { path: 'users', component: () => import('./components/subcomponents/GeReng/sub/MyUsers.vue') },
            { path: 'goods', component: () => import('./components/subcomponents/GeReng/sub/MyGoods.vue') },
            { path: 'orders', component: () => import('./components/subcomponents/GeReng/sub/MyOrders.vue') },
            { path: 'settings', component: () => import('./components/subcomponents/GeReng/sub/MySettings.vue') },
          ]
        },
        { path: 'yishu', component: () => import('./components/subcomponents/YiShu.vue') },
       
      ]
    },
  ]
})

router.beforeEach((to, from, next) => {
  if (to.path === '/home/guanyu' && !localStorage.getItem('token')) {
    next('/login')
  } else {
    next()
  }
})

export default router
